package com.king.oa.view.action;

import java.util.Date;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.king.oa.base.BaseAction;
import com.king.oa.domain.Reply;
import com.king.oa.domain.Topic;
import com.opensymphony.xwork2.ActionContext;

@Controller
@Scope("prototype")
public class ReplyAction extends BaseAction<Reply> {

	private static final long serialVersionUID = 3538520969778545689L;

	private Long topicId;
	
	/** 发表新回复页面 */
	public String addUI() throws Exception {
		//准备数据
		Topic topic = topicService.findById(topicId);
		ActionContext.getContext().put("topic", topic);
		
		return "addUI";
	}

	/** 发表新回复 */
	public String add() throws Exception {
		
		System.out.println(model.getTitle());
		
		//封装
		// >> 表单字段，已经封装了title，content
//		model.setTitle(title);
//		model.setContent(content);
		model.setTopic(topicService.findById(topicId));
		
		// >> 当前信息
		model.setAuthor(getCurrentUser());//当前用户
		model.setIpAddr(ServletActionContext.getRequest().getRemoteAddr());
		model.setPostTime(new Date());//当前时间
		
		//保存
		replyService.save(model);
		
		return "toTopicShow";//发表新回复后转到当前回复主题的显示页面
	}
	
	
	
	/** 删除 */
	public String delete() throws Exception {
		return "toList";
	}

	/** 修改页面 */
	public String editUI() throws Exception {
		return "saveUI";
	}

	/** 修改 */
	public String edit() throws Exception {
		return "toList";
	}

	public Long getTopicId() {
		return topicId;
	}

	public void setTopicId(Long topicId) {
		this.topicId = topicId;
	}
	
}
